home *** CD-ROM | disk | FTP | other *** search
- /***
- *disked.c - disk editor
- *
- *Copyright (c) 1991-1994, Gregg Jennings. All wrongs reserved.
- * P O Box 200, Falmouth, MA 02541-0200
- *
- *Purpose:
- * MS(tm)-DOS Disk EDitor
- *
- *Notice:
- * This progam may be freely used and distributed. Any distrubution
- * with modifications must retain the above copyright statement and
- * modifications noted.
- * No pulp-publication, in whole or in part, permitted without
- * permission (magazines or books).
- *******************************************************************************/
-
- /*
- Versions:
-
- 2.1 04-Jan-1994 added Translate if !Files for startup, Borland
- added 'dir_cluster'
- 2.0 28-Nov-1993
-
- Release Notes:
-
- Programming Notes:
-
- The use of specialized printing functions (conout(), send(), putint()
- et cetera) is because printf() is MUCH to slow on XT's. The screen
- output is significantly faster.
- */
-
- #include <string.h>
- #include <stdio.h>
- #include <conio.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <malloc.h>
- #include <dos.h>
- #include <fcntl.h>
- #include <io.h>
- #include <direct.h>
- #include <process.h>
- #include <errno.h>
-
- #include "disked.h"
- #include "mylib.h"
- #include "diskio.h"
- #include "keys.h"
- #include "files.h"
- #include "alloc.h"
- #include "error.h"
- #include "dirent.h"
- #include "direct.h"
-
- extern char findstr[]; /* for find() */
-
- struct Msg ps[]={ /* for inputing a two argument commnd */
- " from ",6,
- " number ",3,
- };
-
- struct Msg ap[]={ /* for inputing a two argument commnd */
- " from ",3,
- " number ",3
- };
-
- struct Msg st[]={ /* three argument command 's' */
- " track ",3,
- " sector ",2,
- " head ",1
- };
-
- struct Keys kw[]={
- 0,15,"", /* 15 is number of entries -1 */
- ALTD,1, "display",
- ALTG,0, "get",
- ALTH,1, "home",
- ALTM,1, "mask", /* kw[4].s */
- ALTV,1, "verify",
- ALTW,0, "write",
- ALTS,1, "strip", /* kw[7].s */
- ALTC,1, "convert", /* kw[8].s */
- ALTF,0, "files",
- 0, 0, "Debug",
- ALTA,0, "ascii",
- ALTP,1, "partial",
- ALTL,1, "logical",
- ALTT,0, "translate",
- ALTR,10,"radix", /* leave this one last */
- };
-
- #ifndef __BORLANDC__
- #define FILENAME_MAX 63
- #endif
- char comspec[FILENAME_MAX];
- char inifile[FILENAME_MAX];
- char savfile[FILENAME_MAX];
- char curdir[FILENAME_MAX]; /* temp strings, not too big... */
-
- int min_mem; /* testing purposes only, for running */
- /* within an IDE such as MS-QuickC */
-
- unsigned int byte_cnt; /* buffer byte count */
- unsigned int max_bytes; /* maximum buffer size */
- unsigned char *save_sec; /* duplicate sector buffer */
- unsigned char *spare_sec; /* spare sector buffer */
- unsigned char *data_buf; /* pointer to area for data buffer */
- int write_to; /* double protection on write */
- unsigned long tagged[10];
- unsigned int dir_cluster;
-
- int Signon;
- int Save,Restore;
- int files_indexed;
- int find_flag;
-
- int _cdecl main(int argc,char **argv)
- {
- unsigned int c;
- char tmpstr[MAXSTR+1];
- char ccurdir[67];
- unsigned int cdisk;
- register unsigned int u; /* vars for loops */
- register int i;
- unsigned int temps,tempt,temph,tempu;
- long templ;
- int tempd;
- unsigned int bufptr; /* pointer to file buffer */
- int drives[MAX_DRIVE+1]; /* valid drive number array 1-MAX_DRIVE */
- int noput;
- int moved;
- char *bufferfull=" buffer full ";
-
- volume[0]=format[0]=fatsize[0]=tmpstr[0]='\0';
- bufptr = moved = 0;
- noput = TRUE;
-
- dir_cluster = 0;
-
- #ifndef NDEBUG
- printf(""); /* for alloc/free debugging; MSC will call malloc */
- /* during first printf() */
- #endif
- error.num = -1;
-
- cdisk = setup(argv,drives,&disk);
-
- if (Restore)
- {
- if (Display && !Verify)
- print("restoring...");
- if (Verify && getver(" restore",0))
- getinit(savfile);
- else
- Restore=FALSE;
- }
- u = (min_mem) ? 8192U : 65024U;
-
- /* try and get memory */
-
- for (;;u-=512U)
- if ((data_buf=(unsigned char *)alloc(u,sizeof(char)))!=NULL)
- break;
- if (u < 512U*10U)
- quit(NO_MEM);
- max_bytes = u;
-
- getcwd(ccurdir,66); /* save current directory */
- memset(tagged,0,sizeof(tagged));
-
- while ((i=logdisk(disk)) != DISK_OK) /* log disk in */
- {
- printerror(Debug);
- if (disk==cdisk)
- exit(2);
- conout(' ');
- conout(disk+'@');
- conout(':');
- print(" Use current? (or Retry) "); /* get another ? */
- if ((c=input())=='y' || c=='Y')
- disk=cdisk; /* use current drive */
- else if (c!='r' && c!='R')
- exit(0);
- send('\n');
- }
-
- /****** can only alloc sector buffer if sector size is known ******/
-
- if ((sec_buf=alloc(sec_size,sizeof(char)))==NULL)
- quit(NO_MEM);
-
- if ((save_sec=alloc(sec_size,sizeof(char)))!=NULL)
- if ((spare_sec=alloc(sec_size,sizeof(char)))==NULL)
- freep(save_sec);
-
- if (getcwd(curdir,66) == NULL)
- perror("getcwd()");
-
- /* all done with initialization, now check for commands via command line */
-
- /*
- First do Special Commands which bypass normal start-up sequence
- only one for now: /f{text}. Note that the order of /f and +|-f
- on the command line is followed.
- */
-
- if (find_flag) /* find text via command line */
- {
- rootsector();
- if (Display)
- {
- printc(Title); /* display (centered) logo */
- printc(Copyr);
- }
- if (find_flag == 1)
- i = do_files();
- else
- i = 1;
- if (error.num != -1)
- {
- send('\n');
- printerror(Debug);
- send('\n');
- }
- if (i == 0 && Verify)
- i = getver(" find",MOV_YN);
- print("\nfind ");
- print(findstr);
- tempd = find(1,0,0);
- if (tempd >= 0)
- {
- print("found at ");
- pn(tempd,Radix);
- }
- if (find_flag == 2)
- do_files();
- }
- /* end of Special Commands */
- else
- {
- if (Signon == TRUE)
- signon_msg();
- if (Files > 0)
- {
- do_files();
- }
- else if (Signon == TRUE)
- {
- pause();
- send('\n');
- }
- if (!Files)
- get_volume(volume);
- if (Restore) /* if Restored, just read current sector */
- readsector();
- else if (Files && !Home) /* if indexed files and not go home */
- { /* set to current directory */
- strcpy(tmpstr,&curdir[2]);
- if ((tempd=findfile(tmpstr))!=0)
- setcluster(tempd);
- else
- rootsector();
- }
- else if (cdisk == disk)
- {
- templ = cwdstart();
- dir_cluster = sectortocluster(templ);
- setsector(templ);
- }
- else
- rootsector();
-
- if (!(Files && !Home && Translate)) /* display disk parameters */
- dparams(curdir); /* if not dir display */
- print("\n\n\t'/' for help");
- }
-
- if (error.num != -1) /* if error */
- {
- send('\n'); /* place the message */
- send('\n'); /* in a good spot */
- printerror(Debug); /* (before the dump) */
- }
- dumpsector();
-
- /*
- The rest of the code is one huge switch/case in a loop.
-
- The interface I chose to use, a TTY or Teletype-like
- interface (which may seem out dated to some be I find
- it extremely easy to use), presents some programming
- constructs that are hard to keep consistant and can
- be confusing :-)
- */
-
- for (;;)
- {
- if (error.num != -1)
- {
- if (!Verify)
- conout(' ');
- printerror(Debug);
- }
- if (moved)
- {
- moved = 0;
- dumpsector();
- }
- send('\n');
- c=prompt(byte_cnt,Radix);
- if (c<' ')
- {
- conout('^');
- conout(c+'@');
- }
- else if (c<0xff)
- conout(c);
-
- switch(c)
- {
- case '!':
- conout(' '); /* if "File not found" */
- if (spawnl(P_WAIT,comspec,NULL)!=-1)
- moved=1; /* display sec */
- break;
- case SRIGHT: /* shift right arrow */
- case SLEFT: /* shift left arrow */
- if (!Files)
- break;
- tempu=sectortocluster(log_sector);
- if (tempu==0)
- tempu=2;
- temps = (c==SLEFT) ? (-1) : (1);
- if (Display)
- {
- print( (temps==1) ? " next" : " back");
- print(" free cluster");
- }
- for (u=tempu+temps;;u+=temps)
- {
- if (u>=num_clusters)
- u=2;
- if (u<2)
- u=num_clusters;
- if (u==tempu)
- break;
- if (clusters[u] < 1)
- {
- setcluster(u);
- moved=1;
- break;
- }
- }
- break;
-
- case F1:
- if (Files && n_files==1)
- print(" no files");
- else
- {
- print(" Current Directory: ");
- print(curdir);
- send('\n');
- dir();
- }
- break;
- case F2:
- if (!Files)
- break;
- if (n_files==1)
- {
- print(" no files");
- break;
- }
- for (u=1;u<n_files;u++) /* more than 32767 files ? */
- {
- print("\n");
- print(gfile(u));
- if (kbhit())
- {
- if ((c=input())==0)
- input();
- else if (c==0x1b)
- break;
- else if (c==' ')
- pause();
- }
- }
- break;
-
- case SHFTF1:
- dump(sec_buf,0,sec_size,128,Radix);
- break;
- case SHFTF2:
- dumpf(sec_buf,sec_size,Radix);
- break;
- case SHFTF3:
- view(sec_buf,0,sec_size,NOPAUSE,Radix);
- break;
- case SHFTF4:
- dumpdir(sec_buf,sec_size);
- break;
- case SHFTF5:
- dumpboot(sec_buf);
- break;
- case SHFTF6:
- help();
- break;
- case F3:
- if (!Files)
- break;
- conout(' ');
- putuint(n_files-1);
- print(" Files, ");
- putuint(n_dirs);
- print(" Directories");
- break;
- case F4: /* change dir */
- if (Display)
- print("directory ");
- else
- print("cd ");
- if (getstr(tmpstr,MAXSTR,_PUNCT) < 1)
- break;
- if (chdir(tmpstr) == -1)
- print(" not found");
- getcwd(curdir,66);
- break;
- case F5: /* re-read */
- readsector();
- moved = 1;
- break;
- case F6: case F7:
- case F8: case F9:
- if (byte_cnt > (max_bytes-sec_size))
- break;
- if (Display)
- print("append w/");
- tempt = temph = temps = 0;
- switch (c)
- {
- case F6:
- if (Display)
- print(kw[7].s);
- temph = 1;
- break;
- case F7:
- if (Display)
- print(kw[8].s);
- temps = 1;
- break;
- case F8:
- if (Display)
- print(kw[4].s);
- tempt = 1;
- break;
- case F9:
- if (Display)
- print("options");
- tempt = Strip;
- temph = Mask;
- temps = Convert;
- break;
- default:
- break;
- }
- append(tempt,temph,temps,sec_buf,sec_size);
- break;
- case F0:
- if (!Files)
- break;
- if (n_files == 1)
- {
- print(" no files");
- break;
- }
- if (Display)
- print("goto ");
- print("file: ");
- if (getstr(tmpstr,MAXSTR,_PUNCT) < 1)
- break;
- if ((tempu = findfile(tmpstr)) != 0)
- {
- setcluster(tempu);
- moved = 1;
- }
- else
- print(" not found");
- break;
- case ALTA:case ALTC:case ALTD:
- case ALTF:case ALTG:case ALTH:case ALTL:
- case ALTM:case ALTP:case ALTS:case ALTB:
- case ALTV:case ALTW:case ALTT:
- tmpstr[0]='\0';
- for (i=1;i<kw[0].opt;i++)
- if (c==kw[i].key)
- tmpstr[0]=kw[i].s[0];
- if (tmpstr[0]=='\0')
- break;
- if (tmpstr[0]=='w' && !write_to)
- break;
- tmpstr[1]='\0';
- ckey(tmpstr,kw);
- psw(tmpstr[0],kw);
- break;
-
- case '\n': /* **** Display **** */
- header();
- break;
- case '\r':
- if (!Ascii)
- {
- if (Partial)
- dump(sec_buf,(sec_size==128)?(0):(128),sec_size,(sec_size==512)?(384):(sec_size),Radix);
- else
- {
- header();
- dumpf(sec_buf,sec_size,Radix);
- }
- }
- else
- view(sec_buf,0,sec_size,NOPAUSE,Radix);
- break;
-
- case ' ':
- moved=1;
- break;
- case '\b':
- dparams(curdir);
- send('\n');
- break;
- case '?':
- ext_commands();
- break;
- case '/':
- commands();
- break;
- /* **** movement **** */
- case 'H':
- case HOME:
- if (Display)
- print(" home");
- rootsector();
- moved=1;
- break;
- case 'E':
- case END:
- if (Display)
- print(" end");
- lastsector();
- moved=1;
- break;
- case 'b':
- case UP:
- if (Display)
- print(" back sector");
- backsector();
- moved=1;
- break;
- case 'n':
- case DOWN:
- if (Display)
- print(" next sector");
- nextsector();
- moved=1;
- break;
- case 'N':
- case RIGHT:
- if (Display)
- print(" next cluster");
- nextcluster();
- moved=1;
- break;
- case 'B':
- case LEFT:
- if (Display)
- print(" back cluster");
- backcluster();
- moved=1;
- break;
- case 'N'-'@':
- case PGDN:
- if (Display)
- print(" next track");
- nexttrack();
- moved=1;
- break;
- case 'B'-'@':
- case PGUP:
- if (Display)
- print(" back track");
- backtrack();
- moved=1;
- break;
- case 'h':
- if (max_head==1)
- break;
- if (Display)
- print(" next head");
- nexthead();
- moved=1;
- break;
- case 'r':
- case 'R':
- case CTRLR:
- if (c=='R')
- tempd=secs_cluster;
- else
- tempd=1;
- if (Display)
- {
- print(" range ");
- if (c==CTRLR)
- conout('-');
- putbyte(tempd);
- }
- tempd *= (c==CTRLR) ? -1 : 1;
- range(tempd);
- break;
- case '-':
- case '+':
- case '=':
- if (Display)
- print( (c=='-') ? " move back " : " move ahead ");
- if (getlnumb(num_sectors,&templ) <= 0)
- break;
- if (templ == 0)
- break;
- if (c=='-')
- templ *= -1;
- movesector(templ);
- moved = 1;
- break;
- case 'S':
- if (Display)
- print(" cluster ");
- if (getnumb(num_clusters,&tempu) <= 0)
- break;
- if (tempu < 2)
- break;
- setcluster(tempu);
- moved = 1;
- break;
- case 'S'-'@':
- if (Display)
- print(" sector ");
- if (getlnumb(num_sectors,&templ) <= 0)
- break;
- setsector(templ);
- moved=1;
- break;
- case 's':
- tempt=track;
- temps=sector;
- temph=head;
- c=set(st,&tempt,&temps,&temph);
- if (c=='f')
- fatsector();
- else if (c=='b')
- bootsector();
- else if (c==0)
- break;
- else
- {
- if (tempt > max_track)
- tempt = track;
- if (temps > max_sector || temps==0)
- temps = sector;
- if (temph >= max_head)
- temph = head;
- if (tempt==track && temps==sector && temph==head)
- break;
- setphysical(tempt,temps,temph);
- }
- moved=1;
- break;
- /* **** Buffer stuff **** */
- case 'a':
- if (byte_cnt==max_bytes)
- break;
- if (Display)
- print(" append sector");
- if ((byte_cnt+sec_size)>max_bytes)
- {
- print(bufferfull);
- tempu=max_bytes-byte_cnt;
- }
- else
- tempu=sec_size;
- memcpy(data_buf+byte_cnt,sec_buf,tempu);
- byte_cnt+=tempu;
- break;
- case 'A':
- if (log_sector<=data_sector)
- break;
- if (byte_cnt==max_bytes)
- break;
- if (Display)
- print(" append cluster");
- savesector();
-
- i=clustersector(log_sector); /* goto 1st sector */
- if (movesector(-i) != DISK_OK)
- {
- moved = 1;
- restoresector();
- break;
- }
- for (u=0;;u++) /* get it loop */
- {
- if ((byte_cnt+sec_size)>max_bytes)
- tempu=max_bytes-byte_cnt;
- else
- tempu=sec_size;
- memcpy(data_buf+byte_cnt,sec_buf,tempu);
- if ((byte_cnt+=tempu)==max_bytes)
- {
- print(bufferfull);
- break;
- }
- if (u == secs_cluster-1)
- break;
- if (nextsector() != DISK_OK)
- {
- moved = 1;
- break;
- }
- }
- restoresector();
- if (readsector() != DISK_OK)
- moved = 1;
- break;
- case 'A'-'@':
- if (byte_cnt==max_bytes) break;
- if (Display)
- print(" append bytes");
- tempd=temps=0; /* tempd=from, temps=number */
- if (!get(ap,&tempd,&temps))
- break;
- if ((temps+tempd > sec_size) || temps==0)
- break;
- if (byte_cnt+temps > max_bytes)
- break;
- memcpy(data_buf+byte_cnt,sec_buf+tempd,temps);
- if ((byte_cnt+=temps)==max_bytes)
- print(bufferfull);
- break;
-
- case 'u':
- case 'U':
- if (byte_cnt==0)
- break;
- if (Display)
- {
- print(" unappend ");
- print((c=='u')?"sector":"cluster");
- }
- tempu = (c=='u') ? sec_size : cluster_size;
- if (byte_cnt < tempu)
- byte_cnt = 0;
- else
- byte_cnt-=tempu;
- break;
- case 'U'-'@':
- if (byte_cnt==0)
- break;
- if (Display)
- print(" unappend bytes ");
- if (getnumb(byte_cnt,&tempu)<=0)
- break;
- if (byte_cnt < tempu)
- byte_cnt=0;
- else
- byte_cnt-=tempu;
- break;
- case 'e':
- case 'E'-'@':
- if (byte_cnt==0)
- break;
- if (Display || Verify)
- print(" empty buffer");
- if (c=='e' && Verify && !getver("",0))
- break;
- bufptr=byte_cnt=0;
- break;
- case 'k':
- if (save_sec==NULL)
- break;
- if (Display)
- print(" kill changes");
- if (Verify && !getver("",0))
- break;
- memcpy(sec_buf,save_sec,sec_size);
- moved=1;
- break;
- case '>':
- if (spare_sec==NULL)
- break;
- if (Display || Verify)
- print(" store sector");
- if (Verify && !getver("",0))
- break;
- memcpy(spare_sec,sec_buf,sec_size);
- noput=FALSE;
- break;
- case '<':
- if (spare_sec == NULL)
- break;
- if (noput)
- {
- print(" no sector stored");
- break;
- }
- if (Display || Verify)
- print(" retrieve sector");
- if (Verify && !getver("",0))
- break;
- memcpy(sec_buf,spare_sec,sec_size);
- moved = 1;
- break;
- case 'd':
- case 'v':
- if (byte_cnt == 0)
- break;
- if (Display)
- {
- print((c == 'd') ? " dump" : " view");
- print(" file buffer from ");
- }
- if ((tempd = getlnumb(byte_cnt,&tempu)) == ABORT)
- break;
- if (tempd > 0)
- bufptr = tempu;
- if (c == 'd')
- {
- send('\n');
- bufptr = dump(data_buf,bufptr,byte_cnt,256,Radix);
- send('\n');
- }
- else
- bufptr = view(data_buf,bufptr,byte_cnt,PAUSE,Radix);
- break;
- case 'V'-'@':
- if (Display)
- print(" view sector");
- view(sec_buf,0,sec_size,NOPAUSE,Radix);
- break;
- case 'c':
- if (Display)
- print(" change sector buffer from ");
- if (change(sec_buf,sec_size,Radix))
- moved = 1;
- break;
- case 'C':
- if (!byte_cnt)
- break;
- if (Display)
- print(" change file buffer from ");
- change(data_buf,byte_cnt,Radix);
- break;
- case 'D'-'@':
- case 'C'-'@':
- if (changedir(sec_buf,sec_size))
- moved = 1;
- break;
- case 'g': /*** get sectors ***/
- case 'G'-'@': /* uses tempd, tempt, i */
- if (byte_cnt == max_bytes) /* full? */
- break;
- if (Display) /* display */
- {
- print(" get sectors ");
- if (c == 'G'-'@' || Get)
- print("w/move ");
- } /* get number */
- if (getbyte(&tempu) <= 0)
- break; /* tempd = number to get */
- savesector();
- if (tempu==0) /* 0 = get whole track from beginning */
- {
- tempu=max_sector; /* count to get */
- log_sector=logicalsector(track,1,head);
- }
- else if (tempu == 1) /* get rest of track */
- tempu = (max_sector - sector) + 1;
-
- if (log_sector == 0)
- log_sector = num_sectors-1;
- else
- --log_sector;
- if (Display)
- conout(' ');
- for (i = 1 ; i <= (int)tempu ; i++)
- {
- if (kbhit())
- break;
- if (Display)
- {
- pn(i,Radix);
- put(len(i),8);
- }
- if ((tempd=nextsector()) != DISK_OK)
- {
- savecursor();
- if (!Display)
- conout(' ');
- printerror(Debug);
- if (!getver("continue",0))
- {
- put(3,8);
- break;
- }
- restcursor();
- clreol();
- }
- if ((byte_cnt+sec_size)>max_bytes)
- break;
- memcpy(data_buf+byte_cnt,sec_buf,sec_size);
- if ((byte_cnt+=sec_size)==max_bytes)
- {
- print(bufferfull);
- break;
- }
- }
- if (Display && tempd == DISK_OK)
- clreol();
- if (Get || c=='G'-'@')
- {
- moved = 1;
- nextsector();
- }
- else
- {
- restoresector();
- readsector();
- }
- break;
- case 'l': /* **** Log Drive **** */
- case 'L'-'@':
- if (c=='l')
- {
- if (Display)
- print(" disk ");
- c=input();
- if (!isalpha(c))
- break;
- tempd=toupper(c)-'@';
- if (drives[tempd]!=TRUE)
- break;
- conout(toupper(c));
- conout(':');
- if (Verify)
- {
- if (!getver("log disk",MOV_YN))
- break;
- }
- }
- else
- tempd=disk;
- if (newdisk(tempd))
- {
- disk = tempd;
- if (avail_clusters == 0)
- avail_clusters = get_avail_clusters();
- dparams(curdir);
- moved = 1;
- }
- if (error.num != -1) /* if theres gonna be an error */
- {
- if (moved == 1)
- {
- send('\n'); /* put it on a new line */
- send('\n');
- } /* if its bad BOOT, reset diskio flag */
- if (strcmp(error.func,"diskio")==0)/* && error.num == DISK_NREADY)*/
- diskio_error = 0;
- /*printerror(Debug);*/
- }
- break;
-
- /* **** Misc. **** */
-
- case 'T':
- for (i=1;i<10;i++)
- if (tagged[i]!=0L)
- break;
- if (i<10)
- {
- if (Display)
- print(" tagged sector list");
- for (i=1;i<10;i++)
- {
- if (!tagged[i])
- continue;
- conout(' ');
- conout(i+'0');
- conout(':');
- pln(tagged[i],Radix);
- }
- }
- else if (Display)
- print(" no tagged sectors");
- break;
- case 't':
- if (Display)
- print(" number of this tag? ");
- if ((c=input()) < '1' || c > '9')
- break;
- conout(c);
- tagged[c-'0']=log_sector;
- break;
- case 'f':
- case '\\':
- case 'F'-'@':
- if (Display)
- print(" find ");
- tempd=find((c=='f' || c=='\\') ? (1) : (-1),1,(c=='\\') ? 1 : 0);
- if (tempd>=0)
- {
- print("\nfound at ");
- pn(tempd,Radix);
- }
- if (tempd!=ABORT) /* user pressed ESC */
- {
- readsector();
- moved=1;
- }
- break;
- case 'F':
- if (byte_cnt==0)
- break;
- if (Display)
- print(" find ");
- if (find(0,1,0)==-1)
- print(" not found");
- break;
- case 'P':
- if (Display)
- print(" put");
- templ=log_sector;
- temps=0; /* templ=from, temps=number */
- if (!getl(ps,&templ,&temps))
- break;
- if (templ+(long)temps > (long)num_sectors)
- break;
- if (Display)
- print(" file: ");
- else
- conout(':');
- if (getstr(tmpstr,64,_PUNCT) > 0)
- {
- if (Verify)
- {
- if (!getver(" put file",0))
- break;
- }
- if (exist(tmpstr))
- {
- savecursor();
- if (!Verify)
- conout(' ');
- if (!getver("exists, overwrite",0))
- break;
- restcursor();
- clreol();
- }
- if (error.num == -1)
- {
- if (Display && !Verify)
- conout(' ');
- else if (Display && Verify)
- {
- put(3,' ');
- put(3,8);
- }
- putsectors(tmpstr,templ,temps);
- }
- }
- break;
- case 'P'-'@':
- case 'p':
- if (byte_cnt==0)
- break;
- if (Display)
- print(" file: ");
- getstr(tmpstr,64,_PUNCT);
- if (!tmpstr[0])
- break;
- if (Verify)
- {
- print(" put file ");
- if (Display && c=='p')
- print("w/options");
- else if (Display)
- print("w/o options");
- if (!getver("",0))
- break;
- }
- if (access(tmpstr,0) == 0)
- {
- savecursor();
- if (!Verify)
- conout(' ');
- if (!getver("exists, overwrite",0))
- break;
- restcursor();
- clreol();
- if (unlink(tmpstr) == -1)
- break;
- }
- if (error.num != -1)
- break;
- if (Display)
- {
- savecursor();
- if (!Verify)
- conout(' ');
- print("putting");
- restcursor();
- }
- tempd = 1;
- putfile(tmpstr,(c=='p') ? XLATE : NOXLATE,tempd,Mask,Strip,Convert);
- break;
- case 'I'-'@':
- case 'i':
- if (byte_cnt==max_bytes)
- break;
- if (Display)
- print(" file: ");
- getstr(tmpstr,64,_PUNCT);
- if (!tmpstr[0])
- break;
- if (Verify)
- {
- print(" insert file ");
- if (Display && c=='i')
- print("w/options");
- else if (Display)
- print("w/o options");
- if (!getver("",0))
- break;
- }
- if (Display)
- {
- savecursor();
- if (!Verify)
- conout(' ');
- print("inserting");
- restcursor();
- }
- tempd=getfile(tmpstr, (c=='i') ? XLATE : NOXLATE,Mask,Strip,Convert);
- if (tempd == -2)
- {
- if (!Verify)
- conout(' ');
- print("buffer full ");
- }
- break;
- case 'w':
- if (!write_to || !Write)
- {
- print(" write not enabled");
- break;
- }
- if (Display || Verify)
- print(" write sector");
- if (log_sector<dir_sector)
- {
- print("\a Warning! This is ");
- print((log_sector==0)?"the BOOT":"a FAT");
- print(" sector, ");
- if (!getver("write anyway",0))
- break;
- }
- else if (Verify && !getver("",0))
- break;
- writesector();
- break;
- case 'z':
- case 'Z':
- if (Display || c=='Z')
- {
- if (Display)
- print(" parameters");
- dkey(kw);
- if (c=='z')
- send('\n');
- else
- break;
- }
- if (getstr(tmpstr,MAXSTR,_PUNCT)>0)
- ckey(tmpstr,kw);
- break;
- case '0':case '1':case '2':case '3':
- case '4':case '5':case '6':case '7':
- case '8':case '9':
- c-=0x30;
- if (!tagged[c])
- break;
- if (Display || Verify)
- {
- print(" goto sector ");
- pln(tagged[c],Radix);
- }
- if (Verify && !getver("",0))
- break;
- if (log_sector!=tagged[c])
- {
- log_sector=tagged[c];
- readsector();
- moved=1;
- }
- break;
- case ',': /* toggle radix */
- if (Radix==10)
- Radix=16;
- else
- Radix=10;
- if (Display)
- {
- print(" radix is now ");
- print((Radix==16)?"hex":"dec");
- }
- break;
- case 'D':
- if (Debug)
- debug();
- break;
- case CEND:
- if (!Files)
- break;
- tempu = sectortocluster(log_sector);
- if (clusters[tempu] > 0 && (unsigned)clusters[tempu] <= n_files)
- {
- if (Display)
- print(" end file");
- if ((tempu=endfile(clusters[tempu])) > num_clusters)
- break;
- setcluster(tempu);
- moved=1;
- }
- break;
- case CHOME:
- if (!Files)
- break;
- tempu=sectortocluster(log_sector);
- if (clusters[tempu] > 0 && (unsigned)clusters[tempu] <= n_files)
- {
- if (Display)
- print(" home file");
- if ((tempu=homefile(clusters[tempu])) < 2)
- break;
- setcluster(tempu);
- moved=1;
- }
- break;
- case 'm':
- if (!Files)
- break;
- tempu = sectortocluster(log_sector);
- if (clusters[tempu] > 0 && (unsigned)clusters[tempu] <= n_files)
- {
- if (Display)
- print(" map file ");
- print(gfile(clusters[tempu]));
- send('\n');
- mapfile(clusters[tempu],Radix);
- }
- break;
- case 'M':
- if (Files)
- {
- if (Display)
- print(" map free space");
- send('\n');
- mapdisk(Radix);
- }
- break;
- case 'j':
- case 'J':
- case CLEFT:
- case CRIGHT:
- if (!Files)
- break;
- tempu = sectortocluster(log_sector);
- temps = (c=='j' || c==CRIGHT) ? 1 : -1;
- if ((u=jumpfile(tempu,temps)) > 0)
- {
- if (u==tempu)
- break;
- if (Display)
- {
- print((temps==1)?" next":" back");
- print(" file's cluster");
- }
- setcluster(u);
- moved=1;
- }
- break;
- case 'I':
- if (!Files)
- break;
- tempd=sectortocluster(log_sector);
- if (clusters[tempd] < 0 || clusters[tempd] > (int)n_files)
- break;
- if (files[clusters[tempd]].dir)
- {
- print(" can not insert directories");
- break;
- }
- sprintf(tmpstr,gfile(clusters[tempd]));
- if (Display)
- {
- print(" insert file ");
- print(tmpstr);
- }
- if (Verify)
- {
- if (!getver("",0))
- break;
- }
- if (Display)
- {
- savecursor();
- if (!Verify)
- conout(' ');
- print("inserting");
- restcursor();
- }
- if (getfile(tmpstr,XLATE,Mask,Strip,Convert) == -2)
- {
- if (!Verify)
- conout(' ');
- print("buffer full ");
- }
- break;
- case 'Z'-'@':
- if (Display && !Verify)
- print(" saving");
- else if (Verify && !getver(" save",0))
- break;
- saveinit(savfile);
- break;
- case 'X'-'@':
- if (Display && !Verify)
- print(" restoring");
- else if (Verify && !getver(" restore",0))
- break;
- tempd=Home;
- Home=FALSE;
- tempt=disk;
- templ=log_sector;
- if (getinit(savfile))
- {
- if (tempt!=disk)
- {
- if (!newdisk(disk))
- {
- disk=tempt;
- log_sector=templ;
- }
- }
- else if ((unsigned long)templ!=log_sector)
- {
- readsector();
- moved=1;
- }
- else if (Display)
- send('\n');
- }
- else
- {
- disk=tempt;
- log_sector=tempu;
- }
- Home=tempd;
- break;
- case 'X':
- viewfile(savfile);
- break;
- case 'x':
- viewfile(inifile);
- break;
- case 'q':
- case '.':
- case ESC:
- case ALTX:
- case CTRLQ:
- if (Display || Verify)
- print(" exit DISKED");
- if (c!=CTRLQ && Verify && !getver("",0))
- break;
- _dos_setdrive(cdisk,&tempu);
- chdir(ccurdir);
- if (Save && c != CTRLQ)
- {
- if (Verify)
- if (!getver(" save",1))
- break;
- if (Display)
- print(" saving...");
- saveinit(savfile);
- }
- if (files_indexed) /* free calls are for an IDE */
- { /* such as QuickC that I use */
- freep(files);
- freep(clusters);
- }
- if (spare_sec)
- freep(spare_sec);
- if (save_sec)
- freep(save_sec);
- freep(sec_buf);
- freep(data_buf);
- return(0);
- break;
- default:
- break;
- }
- }
- }
-